<template>
	<view>
		<view class="settlement">
			<view v-for="item in orderList">
				<view class="middle" >
					<view class="right">
						<image :src="type == 'single' ? (imgPath + item.taskUser.user.avatar) : (imgPath + item.orderUser.avatar)" mode="aspectFill"></image>
						<view>
							<view>
								<text>{{ type == 'single' ? item.taskUser.user.userName : item.orderUser.userName }}</text>
								<image v-if="type != 'single'" :src="item.orderUser.sex==1 ? '/static/icon1/21.png' : '/static/icon1/55.png'" mode="aspectFill"></image>
								<image v-if="type == 'single'" :src="item.taskUser.user.sex==1 ? '/static/icon1/21.png' : '/static/icon1/55.png'" mode="aspectFill"></image>
							</view>
							<view class="job-info" v-if="item.taskType === 0">
								<view>
									<text>开工时间</text>
									<text>{{ item.startTime.slice(11, 16) }} — {{ item.endTime.slice(11, 16)}}</text>
								</view>
								<view>
									<text>工作时长</text>
									<text>{{ item.finishCount }}小时</text>
								</view>
								<view>
									<text>工作单价</text>
									<text>{{ item.reward.divide(100)}}元/小时</text>
								</view>
							</view>
							<view class="job-info type1" v-if="item.taskType === 1">
								<view>
									<view>
										<text>开工时间</text>
										<text>{{ item.startTime.slice(11, 16) }}</text>
									</view>
									<view>
										<text>收工时间</text>
										<text>{{ item.endTime.slice(11, 16)}}</text>
									</view>
								</view>
								<view>
									<view>
										<text>工作单价</text>
										<text>{{ item.reward }}元/件</text>
									</view>
									<view>
										<text>完成件数</text>
										<text>{{ item.finishCount }}</text>
									</view>
								</view>
							</view>
							<view class="job-info" v-if="item.taskType === 2">
								<view>
									<view>
										<text>开工时间</text>
										<text>{{ item.startTime.slice(11, 16) }}</text>
									</view>
									<view>
										<text>收工时间</text>
										<text>{{ item.endTime.slice(11, 16)}}</text>
									</view>
								</view>
								<view>
									<view>
										<text>工作单价</text>
										<text>{{ item.reward }}元/天</text>
									</view>
									<view>
										<text>完成天数</text>
										<text>{{ item.finishCount }}天</text>
									</view>
								</view>
								
							</view>
						</view>
					</view>
				</view>
				<view class="settlement-bottom">
					<text>小计</text>
					<text>{{ type == 'single' ? orderAmount/100 : item.finishAmountD/100 }}</text>
					<text>{{'元'}}</text>
				</view>	
						
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderAmount: '',//单个订单金额
				type: '',//单个结算订单类型single
				orderId: '',//单个结算订单id'
				imgPath:'',//图片路径
				taskDTO: { //任务结算上传参数
				  "couponId": '',
				  "orderParam": {},//'订单id': 'finishAmount'
				  "payPwd": "",
				  "payType": 5,//0支付宝，1微信，2钱包
				  "taskId": '',
				},
				requestObj: { //获取同一任务订单列表参数
					pageNum: 1,
					pageSize: 1000,
					status: 4,//待结算
					statusIn: '4',
					taskId: '',
				},
				orderList: [{ //订单列表
					orderUser: {},
					taskUser: {user:{}}
				}] ,
			}
		},
		methods: {
			//获取我的零工订单列表
			async order_list_by_taskId () {
				this.requestObj.taskId = this.taskDTO.taskId
				let res = await this.$fetch(this.$api.order_list_by_taskId, this.requestObj, 'POST')
				if (res.code) return uni.showToast({ title: res.msg, icon: 'none' })
				res.rows.forEach( item => {
					item.reward = item.reward.divide(100)
					item.finishAmountD = this.taskDTO.orderParam[item.id]*100
				})
				this.orderList = res.rows
				// console.log('this.orderList',this.orderList)
			},
		
			// 获取订单详情
			async order_detail() {
				let res = await this.$fetch(this.$api.order_detail, { orderId: this.orderId}, 'POST')
				if (res.code) return uni.showToast({ title: res.msg, icon: 'none' })
				// 整理数据,res.data.user为null，则改为""
				 Object.getOwnPropertyNames(res.data).forEach(function(key){
					res.data[key] = res.data[key] == null ? '' : res.data[key]
				})
				this.orderList = [res.data]
				console.log('this.orderList',this.orderList)
			},
		},
		onLoad(options) {

			this.imgPath = uni.getStorageSync('imgPath')
			if(options.type == 'single') {
				this.type = 'single'
				this.orderId = options.orderId
				this.orderAmount = options.orderAmount
			}else {
				this.taskDTO = JSON.parse(options.taskDTO)
				console.log('统一明细页面参数',this.taskDTO)
			}
		},
		onShow() {

			if(this.type == 'single') {
				this.order_detail()
			}else {
				this.order_list_by_taskId()
			}
		}
	}
</script>

<style lang="less">
	.settlement {
		& > view {
			margin-top: 30rpx;
			padding: 30rpx 30rpx 0;
			background-color: #FFFFFF;
			& > .middle {
				display: flex;
				justify-content: space-between;
				& > .right {
					display: flex;
					margin-bottom: 20rpx;
					& > image {
						width: 108rpx;
						height: 108rpx;
						border-radius: 50%;
						margin-right: 30rpx;
					}
					& > view {
						display: flex;
						flex-direction: column;
						margin-bottom: 10rpx;
						& > view:first-child {
							margin-bottom: 20rpx;
							& > text {
								margin-right: 20rpx;
								height: 48rpx;
								font-size: 17px;
								color: #402110 !important;
							}
							& > image {
								width: 26rpx;
								height: 26rpx;
							}
						}
						& > .job-info {
							& > view {
								display: flex;
								margin-bottom: 10rpx;
								& > view:first-child {
									// border: 1px solid #000000;
									width: 280rpx;
								}
								text:first-child {
									color: rgba(64,33,16,0.70);
									margin-right: 20rpx;
								}
							}
							
						}
					}
				}
			}
			& > .settlement-bottom {
				// border: 1px solid #000000;
				height: 100rpx;
				display: flex;
				align-items: center;
				justify-content: flex-end;
				color: rgba(64,33,16,0.50);
				border-top: 1px solid #F2F2F2;
				text:nth-child(2) {
					// border: 1px solid #000000;
					margin-left: 30rpx;
					font-size: 17px;
					color: #FF650C;
				}
			}		
				
		}
		
	}

</style>
